package user.zc.excel.data.style;

import user.zc.helper.ExcelAssistant;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

public interface IStyle {

    @Data
    @Builder
    @Accessors(chain = true)
    class StyleInfo implements Cloneable{
        private short color = -1;
        private FontInfo font = null;
        private int sort= -1;
        private int width = -1;
        private int precision = -1;
        private short alignment = -1;
        private boolean wrapText = false;
        @Override
        public StyleInfo clone() throws CloneNotSupportedException {
            StyleInfo clone = (StyleInfo)super.clone();
            clone.setFont(this.getFont().clone());
            return clone;
        }
        public static StyleInfo newEmpty(){
            return new StyleInfo((short) -1,new FontInfo((short)-1,(short)-1,"",false),-1,-1,-1,(short) -1,false);
        }
        public static StyleInfo create(ExcelAssistant.Style style){
            return StyleInfo.builder()
                    .color(style.color())
                    .sort(style.sort())
                    .width(style.width())
                    .precision(style.precision())
                    .alignment(style.alignment())
                    .wrapText(style.wrapText())
                    .font(FontInfo.create(style.font()))
                    .build();
        }

        public StyleInfo extend(StyleInfo styleInfo){
            if(styleInfo.color!=-1){
                this.setColor(styleInfo.color);
            }
            if(styleInfo.sort!=-1){
                this.setSort(styleInfo.sort);
            }
            if(styleInfo.width!=-1){
                this.setWidth(styleInfo.width);
            }
            if(styleInfo.precision!=-1){
                this.setPrecision(styleInfo.precision);
            }
            if(styleInfo.getFont().color!=-1){
                this.getFont().setColor(styleInfo.font.color);
            }
            if(styleInfo.getFont().height!=-1){
                this.getFont().setHeight(styleInfo.font.height);
            }
            if(!"".equals(styleInfo.getFont().name)){
                styleInfo.getFont().setName(styleInfo.getFont().name);
            }
            if(styleInfo.wrapText!=false){
                this.setWrapText(styleInfo.wrapText);
            }
            this.getFont().setBold(styleInfo.getFont().bold);
            return this;
        }
    }
    @Data
    @Builder
    @Accessors(chain = true)
    class FontInfo implements Cloneable{
        short color = -1;
        short height = -1;
        String name = "";
        boolean bold = false;
        @Override
        public FontInfo clone() throws CloneNotSupportedException {
            return (FontInfo)super.clone();
        }
        public static FontInfo create(ExcelAssistant.Style.Font font){
            return FontInfo.builder()
                    .color(font.color())
                    .height(font.height())
                    .name(font.name())
                    .bold(font.bold()).build();
        }

    }


    StyleInfo parse(ExcelAssistant.Style style);
}
